package com.sfac.java_spring_boot_02.modules.test.dao;


import com.sfac.java_spring_boot_02.modules.test.entity.Student;
import org.apache.ibatis.annotations.Param;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Description StudentDao
 * @Author HymanHu
 * @Date 2021/9/14 14:56
 */
@Repository
public interface StudentDao extends JpaRepository<Student, Integer> {
    Student findTopByStudentNameAndEmail(String studentName,String email);

    @Query(nativeQuery = true, value = "select * from test_student" +
            "where studentName like:studentName or email like:email")
    List<Student> getStudentsByStudentNameOrEmail(@Param("studentName") String studentName, @Param("email") String email);

    @Query(nativeQuery=true, value="insert into test_student(student_name,age,email) " +
            "values(:#{#student.sutdentName},:#{#studentName,:age},:#{#student.email})")
    @Modifying
    void insertStudent(@Param("student")Student student);
}
